package org.example.socket;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;

public class QQServer {
    public static void main(String[] args) throws IOException {

        // 创建一个服务器
        ServerSocket serverSocket = new ServerSocket();
        // 服务区绑定一个端口
        serverSocket.bind(new InetSocketAddress(8888));
        System.out.println("服务区开始启动监听端口8888");
        // 服务区傻傻等待端口消息
        Socket accept = serverSocket.accept();
        // 如果有消息来了就用流接受
        InputStream inputStream = accept.getInputStream();
        byte[] buff = new byte[1024];
        int len ;
        while ((len = inputStream.read(buff)) != -1) {
            System.out.println(new String(buff,0,len));
        }

        inputStream.close();

    }
}
